<?php
	if ( sizeof($_POST) > 0 )
	{
		$eeRO_data = array('user_pass' => $_POST['user_pass'], 'user_pass_new' => $_POST['user_pass_new'], 'user_pass_copy' => $_POST['user_pass_copy']);
		$eeRO_error = array();
		
		if ( !preg_match('/^[0-9a-z_]{4,32}$/i', $eeRO_data['user_pass']) )
		{
			$eeRO_error['user_pass'] = true;
		}
		
		if ( !preg_match('/^[0-9a-z_]{4,32}$/i', $eeRO_data['user_pass_new']) )
		{
			$eeRO_error['user_pass_new'] = true;
		}
		
		if ( $eeRO_data['user_pass_new'] != $eeRO_data['user_pass_copy'] )
		{
			$eeRO_error['user_pass_copy'] = true;
		}
		
		if ( sizeof($eeRO_error) > 0 )
		{
			$eeRO_view->assign('error', $eeRO_error);
			$eeRO_view->assign('module', array('title' => 'Изменение данных', 'template' => 'account_change.html'));
		}
		else
		{
			$eeRO_data['password'] = ( $eeRO_config->options['md5'] ) ? md5($eeRO_data['user_pass']) : $eeRO_data['user_pass'];
			$eeRO_base_ragnarok->query('SELECT `account_id` FROM `login` WHERE `user_pass`=:user_pass AND `account_id`=:account_id', array(':user_pass' => $eeRO_data['password'], ':account_id' => $eeRO_user['account_id']));
			if ( $eeRO_base_ragnarok->num() > 0 )
			{
				$eeRO_data['password'] = ( $eeRO_config->options['md5'] ) ? md5($eeRO_data['user_pass_new']) : $eeRO_data['user_pass_new'];
				$eeRO_base_ragnarok->query('UPDATE `login` SET `user_pass`=:user_pass WHERE `account_id`=:account_id', array(':user_pass' => $eeRO_data['password'], ':account_id' => $eeRO_user['account_id']));
				$eeRO_view->assign('module', array('title' => 'Изменение данных', 'template' => 'account_change_yes.html'));
			}
			else
			{
				$eeRO_view->assign('error', array('user_pass_error' => true));
				$eeRO_view->assign('module', array('title' => 'Изменение данных', 'template' => 'account_change.html'));
			}
		}
	}
	else
	{
		$eeRO_view->assign('module', array('title' => 'Изменение данных', 'template' => 'account_change.html'));
	}